var grounded : boolean = true;
var midairfire : boolean = false;
var characterMotor : CharacterMotor;

function Start() {
	characterMotor = GetComponent(CharacterMotor);
}

function Update () {
   var up = transform.TransformDirection(Vector3.forward);
   var hit : RaycastHit;    
   Debug.DrawRay(transform.position, up * 2, Color.green);
  
	if (Input.GetButtonDown("Jump")) {
		animation.wrapMode = WrapMode.Once;
		animation.CrossFade("Jump");	
		grounded = false; 
	}
	      
	if(characterMotor.IsGrounded()) {
		if (Input.GetAxis("Horizontal") != 0) {
			animation.wrapMode = WrapMode.Loop;
			animation.CrossFade("Walkcycle");
			if(Input.GetAxis("Fire1")) {
				animation.wrapMode = WrapMode.Once;
				animation.Play("ArmaAction");
				}
		}
		else {
			animation.wrapMode = WrapMode.Loop;
			animation.CrossFade("Idle");
			if(Input.GetAxis("Fire1")) {
				animation.wrapMode = WrapMode.Once;
				animation.Play("ArmaAction");
				}
		}
	}
	else {
		if(Physics.Raycast(transform.position, up, hit, 2)) {
			Debug.Log("Hit");    
			if(hit.collider.gameObject.name == "ground") {
				animation.wrapMode = WrapMode.Once;
				animation.CrossFade("Land");	
				grounded = true; 
				if(Input.GetAxis("Fire1")) {
					animation.wrapMode = WrapMode.Once;
					animation.Play("FireDown");
					}
			}
		}
		else {
				if(Input.GetButton("Fire1")) {
					if(animation.IsPlaying("FireDown")) {
						animation.wrapMode = WrapMode.Once;
						animation.Play("FireDown");
						midairfire = true;
						}
					}
				else {
					midairfire = false;
					}
				if(midairfire == false) {
						animation.wrapMode = WrapMode.Once;
						animation.CrossFade("Caer");	
						grounded = false; 
						}
					
				}
				
			}
		}



